package com.uft.was.connector;

import java.io.File;
import java.security.Security;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.ibm.icu.util.Calendar;
import com.ibm.websphere.management.AdminClient;
import com.ibm.websphere.management.AdminClientFactory;
import com.ibm.websphere.management.Session;
import com.ibm.websphere.management.configservice.ConfigService;
import com.ibm.websphere.management.configservice.ConfigServiceHelper;
import com.ibm.websphere.management.configservice.ConfigServiceProxy;
import com.ibm.websphere.management.exception.ConfigServiceException;
import com.ibm.websphere.management.exception.ConnectorException;
import com.ibm.ws.scripting.WasxShell;
import com.ibm.wsspi.ssl.RetrieveSignersHelper;
import com.uft.utils.UftUtils;
import com.uft.was.config.CustomPropertyDetails;
import com.uft.was.config.ObjectFactory;
import com.uft.was.config.PropertyDetails;
import com.uft.was.config.Xml;
import com.uft.was.config.YesNoDefinition;

public class WasConnectorManager {
	private  static Logger  logger = Logger.getLogger(WasConnectorManager.class);
	private boolean registerListener=true;
	private AdminClient adminClient;
	private ConfigService configService;
	private String hostname="localhost";
	private String profileName;
	private String region;
	private String port="9060";
	private Boolean security = false;
	private String username;	
	private String password;
	private String soapCfgURL;
	private String sslCfgURL;	
	private String trustStore;
	private String trustPassword;
	private String keyPassword;
	private String keyStore;
	private String wasInstallPath;
	private String rootFolder;
	private String soapRequestTimeout="180";
	private boolean connected=false;
	private String configScript="configure.py";
	private String wsadminClasspath="";
	private WasManagementListener listener;
	private Date initDate= Calendar.getInstance().getTime();
	
	public WasConnectorManager(){
		 soapCfgURL = "soap.client.props";
	     sslCfgURL = "ssl.client.props";
	     trustStore="ClientTrustFile.jks";
	     keyStore="ClientKeyFile.jks";
	     rootFolder=System.getProperty("user.home");
	     wasInstallPath=rootFolder;
	     listener= new WasManagementListener();
	 }
	public boolean initialiazeConnection(){
		return initializeConnection(hostname,port, security,username,password);
	}
	public boolean initializeConnection(String host,String port, boolean security,String user, String pass){
		logger.debug("initialize Connection...");
		if(!StringUtils.isNotBlank(host)){
			logger.error("Deployment Manager Hostname is Not valid");
			return false;
		}
		if(!UftUtils.hostExists(host)){
			logger.error("Host :"+host+ " Does't exists ");
			return false;
		}
		logger.debug("Hostname : "+host);
		this.hostname=host;
		 if(!StringUtils.isNotBlank(port)){
			 logger.error(" Deployment Manager Port is not Valid ");
			 return false;
		 }
		 logger.debug("Port : "+port);
		 this.port=port;
		if(security){
			 this.security=security;
			 logger.debug("security : "+security);
		 }
		if(StringUtils.isNotBlank(user) && StringUtils.isNotBlank(pass)){
			logger.debug("Setting Security TRUE ");
			this.username=user;
		    this.password=pass;
			this.security=true;
			
		}else{
			 logger.warn("User or password is invalid. Setting Security FALSE ");
			 this.security=false;
		 }
		if(wasInstallPath != null){
			logger.debug("wasInstallPath is availble:  Setting:  was.install.root &  user.root = ${was.install.root}/etc/");
			System.setProperty("was.install.root", wasInstallPath);
	        System.setProperty("user.root", (new StringBuilder(String.valueOf(wasInstallPath))).append("/etc/").toString());
	        if(soapCfgURL.equalsIgnoreCase("soap.client.props")){
	        	logger.debug("SOAP Config File  not provided... setting default");
	        	soapCfgURL = (new StringBuilder("file:")).append(wasInstallPath).append("/properties/").append(soapCfgURL).toString();
	        	logger.debug("soapCfgURL: "+soapCfgURL);
	        }
	        if(sslCfgURL.equalsIgnoreCase("ssl.client.props")){
	        	logger.debug("SSL Config File not provided... setting default");
	        	sslCfgURL = (new StringBuilder("file:")).append(wasInstallPath).append("/properties/").append(sslCfgURL).toString();
				logger.debug("sslCfgURL: "+sslCfgURL);
	        	
	        }
		}
//		if(soapCfgURL.indexOf("file:") < 0 && sslCfgURL.indexOf("file:") < 0){
//			logger.debug("SOAP Config File and SSL Config File not provided... setting default");
//			soapCfgURL = (new StringBuilder("file:")).append(wasInstallPath).append("/properties/").append(soapCfgURL).toString();
//			logger.debug("soapCfgURL: "+soapCfgURL);
//			sslCfgURL = (new StringBuilder("file:")).append(wasInstallPath).append("/properties/").append(sslCfgURL).toString();
//			logger.debug("sslCfgURL: "+sslCfgURL);
//		}
		logger.info("soapCfgURL "+soapCfgURL);
		logger.info("sslCfgURL "+sslCfgURL);
		initializeEnv();
		Properties props = new Properties();
		//props.put("host", host);
		//props.put("port", port);
		props.put(AdminClient.CACHE_DISABLED, "true");
		props.put(AdminClient.CONNECTOR_HOST, host);
		props.put(AdminClient.CONNECTOR_PORT, port);
		props.put(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);
	    props.put(AdminClient.CONNECTOR_SOAP_REQUEST_TIMEOUT, soapRequestTimeout);
	    if(security){
			 props.setProperty(AdminClient.CONNECTOR_SECURITY_ENABLED, Boolean.toString(true));
	         props.setProperty(AdminClient.USERNAME, user);
	         props.setProperty(AdminClient.PASSWORD, pass);
		}
	    if(System.getProperty("java.vendor").contains("Sun") || System.getProperty("java.vendor").contains("Oracle")){
			 Security.setProperty("ssl.SocketFactory.provider", "sun.security.ssl.SSLSocketFactoryImpl");
		     Security.setProperty("ssl.ServerSocketFactory.provider", "sun.security.ssl.SSLSocketFactoryImpl");
		 }
	    if(security){
			 RetrieveSignersHelper.getInstance().autoAcceptSignerAndStoreInTrustStore();
		 }
	    try{
			logger.info("Connecting to : "+ host+" Port: "+port+" securit: "+security+ " UserName: "+username);
			adminClient = AdminClientFactory.createAdminClient(props);
			initDate= Calendar.getInstance().getTime();
			if(adminClient != null){
				if(registerListener){
					logger.info("Registering Listener.....");
					listener.registerStatusNotificationListener(adminClient);
				}
				connected=true;
				logger.info(adminClient.getDefaultDomain()+ " Mbean Count: "+adminClient.getMBeanCount());
				
				return true;
			}
		} catch (ConnectorException e) {
			// TODO Auto-generated catch block
			connected=true;
			e.printStackTrace();
		}
	    
		return false;
	}
	public boolean checkConnected(){
		 if(adminClient != null){
			 try {
				if(adminClient.getDefaultDomain() != null){
					connected=true;
					 return true;
				 }
			} catch (ConnectorException e) {
				// TODO Auto-generated catch block
				connected=false;
				e.printStackTrace();
			}
		 }
		 
		 return false;
	 }
	public boolean testConnectionOnly(){
		registerListener=false;
		initialiazeConnection();
		return checkConnected();
	 }
	public void retryConnection(int times){
		for(int i=0; i< times; i++){
			initialiazeConnection();
			if(checkConnected()){
				break;
			}
		}
		
	}
	public String getCellName()
	  {
		 if(adminClient == null)
			 return null;
		 
	    try {
			return adminClient.getServerMBean().getKeyProperty( "cell" );
		} catch (NullPointerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ConnectorException e) {
			// TODO Auto-generated catch block SitescopeAlertManager
			e.printStackTrace();
		}
	    return null;
	  }
	public List<HashMap<String,String>> getNodes(){
		List<HashMap<String,String>> nodes = new ArrayList<HashMap<String,String>>();
		Session session;
		String cell=getCellName();
		try {
			session = new Session();
			ObjectName nodePattern = ConfigServiceHelper.createObjectName(null, "Node");
			ObjectName serverPattern = ConfigServiceHelper.createObjectName(null, "ServerIndex");
			ObjectName configData[] = getConfigService().queryConfigObjects(session, null, nodePattern, null);
			for(int i = 0; i < configData.length; i++){
				String nodeName = ConfigServiceHelper.getDisplayName(configData[i]);
				ObjectName nodeScope = getConfigService().resolve(session, (new StringBuilder("Node=")).append(nodeName).toString())[0];
				ObjectName serversData[] = getConfigService().queryConfigObjects(session, nodeScope, serverPattern, null);
				HashMap<String,String> hashTemp= new HashMap<String,String>();
				hashTemp.put("name", nodeName);	
				hashTemp.put("cellName", cell);
				nodes.add(hashTemp);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return nodes;
	}
	public List<HashMap<String,String>> getServersByNode(String nodeName){
		 List<HashMap<String,String>> nodes = new ArrayList<HashMap<String,String>>();
			Session session;
			String cell=getCellName();
			try{
				session = new Session();
				ObjectName serverPattern = ConfigServiceHelper.createObjectName(null, "ServerIndex");
				ObjectName nodeScope = getConfigService().resolve(session, (new StringBuilder("Node=")).append(nodeName).toString())[0];
				ObjectName serversData[] = getConfigService().queryConfigObjects(session, nodeScope, serverPattern, null);
				for(int j = 0; j < serversData.length; j++){
					List serverEntries = (ArrayList)getConfigService().getAttribute(session, serversData[j], "serverEntries");
					for(Iterator iterator = serverEntries.iterator(); iterator.hasNext();){
						AttributeList serverAttr = (AttributeList)iterator.next();
						String serverType = (String)ConfigServiceHelper.getAttributeValue(serverAttr, "serverType");
						String serverName = (String)ConfigServiceHelper.getAttributeValue(serverAttr, "serverName");
						HashMap<String,String> hashTemp= new HashMap<String,String>();
						hashTemp.put("serverName", serverName);
						hashTemp.put("serverType", serverType);
						hashTemp.put("cellName", cell);
						nodes.add(hashTemp);
						
					}
				}
			}catch(Exception e){
				e.printStackTrace();
			}
			return nodes;
		}
	public List<HashMap<String,String>> getAllServers(){
		 List<HashMap<String,String>> servers = new ArrayList<HashMap<String,String>>();
		 String cell=getCellName();
		 Session session;
			try {
				session = new Session();
				ObjectName nodePattern = ConfigServiceHelper.createObjectName(null, "Node");
				ObjectName serverPattern = ConfigServiceHelper.createObjectName(null, "ServerIndex");
				ObjectName configData[] = getConfigService().queryConfigObjects(session, null, nodePattern, null);
				for(int i = 0; i < configData.length; i++){
					String nodeName = ConfigServiceHelper.getDisplayName(configData[i]);
					ObjectName nodeScope = getConfigService().resolve(session, (new StringBuilder("Node=")).append(nodeName).toString())[0];
					ObjectName serversData[] = getConfigService().queryConfigObjects(session, nodeScope, serverPattern, null);
		
					
					for(int j = 0; j < serversData.length; j++){
						List serverEntries = (ArrayList)getConfigService().getAttribute(session, serversData[j], "serverEntries");
						String hostName = (String)getConfigService().getAttribute(session, serversData[j], "hostName");
						for(Iterator iterator = serverEntries.iterator(); iterator.hasNext();){
							AttributeList serverAttr = (AttributeList)iterator.next();
							
							String serverType = (String)ConfigServiceHelper.getAttributeValue(serverAttr, "serverType");
							String serverName = (String)ConfigServiceHelper.getAttributeValue(serverAttr, "serverName");
							
							if(serverType.equalsIgnoreCase("APPLICATION_SERVER")){
								logger.debug("serverName: "+serverName+ "   serverType: "+serverType);
								HashMap<String,String> hashTemp= new HashMap<String,String>();
								hashTemp.put("serverName", serverName);
								hashTemp.put("serverType", serverType);
								hashTemp.put("nodeName", nodeName);
								hashTemp.put("hostName", hostName);
								hashTemp.put("cellName", cell);
								servers.add(hashTemp);
							}
							
						}
					 }
					
				}
					
			}catch(Exception e){
				e.printStackTrace();
			}
			return servers;
		}
	public String getServerStatus(String nodeName, String serverName){
		  logger.info("serverName: "+serverName+ "   nodeName: "+nodeName);
			String processStatus="UNKNOWN";
			if(adminClient == null)
	                 return "UNKNOWN";
	             
			try {
				ObjectName nodeAgentObj=getNodeMbeanObj(nodeName);
				String opName = "getProcessStatus";
				String signature[] = { "java.lang.String" };
				String params[] = { serverName };
	             if(nodeAgentObj != null){
	                 processStatus=(String)adminClient.invoke(nodeAgentObj, opName, params, signature);
	             }else{
	            	 logger.error("Nodeagent is not running:  "+nodeName);
	             } 	
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				processStatus="UNKNOWN";
			} 
			
			return processStatus;
		}
	public boolean stopServer(String nodeName, String serverName){
	     String status=getServerStatus(nodeName,serverName);
	     Boolean processStatus=false;
	     if(status.equalsIgnoreCase("RUNNING")){
	         try {
	             ObjectName serverMbean=getServerMBean(nodeName, serverName);
	             String opName = "stop";
	             String signature[] = null;
	             String params[] = null;
	             adminClient.invoke(serverMbean, opName, params, signature);
	             processStatus=true;
	         }catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			processStatus=false;
		} 
	     }
	     return processStatus;
	    
	     
	 }
	public boolean startServer(String nodeName,String serverName, int waitTime){
	     String status=getServerStatus(nodeName,serverName);
	     Boolean processStatus=false;
	     if(status.equalsIgnoreCase("STOPPED")){
	         try {
			ObjectName nodeAgentObj=getNodeMbeanObj(nodeName);
			String opName = "launchProcess";
			String signature[] = { "java.lang.String", "java.lang.Integer" }; 
			Object params[] = { serverName, new Integer(waitTime) }; 
	                 if(nodeAgentObj != null){
	                     processStatus=(Boolean)adminClient.invoke(nodeAgentObj, opName, params, signature);
	                 }
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			processStatus=false;
		} 
	     }
	     
	     return processStatus;
	 }
	private ObjectName getServerMBean(String nodeName, String serverName) throws ConnectorException {
	     ObjectName serverMBean=null;
	        try {
	            StringBuffer oNameQuery= new StringBuffer(41);
	                oNameQuery.append("WebSphere:*");
	                oNameQuery.append(",type=").append("Server");
	                oNameQuery.append(",node=").append(nodeName);
	                oNameQuery.append(",process=").append(serverName);
	            ObjectName partialName = new ObjectName(oNameQuery.toString());
	            Set s = adminClient.queryNames(partialName, null);
	            if (!s.isEmpty()) {
	                serverMBean = (ObjectName) s.iterator().next();
	            }
	        } catch (MalformedObjectNameException exc) {
	            // will not occur
	            exc.printStackTrace();
	        }
	    return serverMBean;
	   }
	private ObjectName getNodeMbeanObj(String nodeName) throws MalformedObjectNameException, NullPointerException, ConnectorException{
		ObjectName nodeObj;
		ObjectName queryName= new ObjectName("WebSphere:type=NodeAgent,node=" + nodeName + ",*");
		Set s = adminClient.queryNames(queryName, null); 
		if (!s.isEmpty()){
			nodeObj = (ObjectName)s.iterator().next();
			//adminClient.invoke()
			return nodeObj;
		}
		else{ 
			return null;
		}
	}
	public ConfigService getConfigService() {
		logger.debug("getting ConfigService");
		if(configService == null){
			 try
	         {
	             configService = new ConfigServiceProxy(adminClient);
	             logger.debug("get the ConfigService");
	         }
	         catch(InstanceNotFoundException e)
	         {
	        	 logger.error(e.getMessage(), e);
	             e.printStackTrace();
	         }
	         catch(ConnectorException e)
	         {
	        	 logger.error(e.getMessage(), e);
	             e.printStackTrace();
	         }
			 
		 }
		 return configService;
	}
	public void initializeEnv(){
		 System.setProperty("com.ibm.SOAP.ConfigURL", soapCfgURL);
	     System.setProperty("com.ibm.SSL.ConfigURL", sslCfgURL);
	     System.setProperty("org.apache.soap.util.net.SSLUtils.buildSSLSocket.timeout", soapRequestTimeout);
	     System.setProperty("com.ibm.SOAP.requestTimeout", soapRequestTimeout);
	     System.setProperty("sun.net.client.defaultConnectTimeout", soapRequestTimeout);
	     System.setProperty("sun.rmi.transport.proxy.connectTimeout", soapRequestTimeout);
	     System.setProperty("com.ibm.ws.management.connector.soap.keepAlive", "true");
	     System.setProperty("com.ibm.websphere.thinclient", "true");
	 }
	
	public int runScript(String script, String parms){
		logger.info("runScript");
		if(script.equalsIgnoreCase("")){
			script=configScript;
		}
		
		 WasxShell shell = new WasxShell();
		 RetrieveSignersHelper.getInstance().autoAcceptSignerAndStoreInTrustStore();
		 if(wasInstallPath != null){
			 logger.info("wasInstallPath: "+wasInstallPath);
			 if(soapCfgURL.equalsIgnoreCase("soap.client.props")){
	        	logger.info("SOAP Config File  not provided... setting default");
	        	soapCfgURL = (new StringBuilder("file:")).append(wasInstallPath).append("/properties/").append(soapCfgURL).toString();
	        	logger.info("soapCfgURL: "+soapCfgURL);
	        }
	        if(sslCfgURL.equalsIgnoreCase("ssl.client.props")){
	        	logger.info("SSL Config File not provided... setting default");
	        	sslCfgURL = (new StringBuilder("file:")).append(wasInstallPath).append("/properties/").append(sslCfgURL).toString();
				logger.info("sslCfgURL: "+sslCfgURL);
	        	
	        }
		 }
		 File scriptFile= new File(script);
		 if(wasInstallPath != null)
        {
            System.setProperty("was.install.root", wasInstallPath);
            System.setProperty("user.root", (new StringBuilder(String.valueOf(wasInstallPath))).append("etc/").toString());
        }
		System.setProperty("com.ibm.SOAP.ConfigURL", soapCfgURL);
	    System.setProperty("com.ibm.SSL.ConfigURL", sslCfgURL);
	    System.setProperty("org.apache.soap.util.net.SSLUtils.buildSSLSocket.timeout", "6000000");
	    System.setProperty("SCRIPTPATH",scriptFile.getParent());
	    try
        {
	    	String[] params=parms.split(",");
	    	ArrayList<String> stringList = new ArrayList<String>();
	    	stringList.add("-connType");
	    	stringList.add("SOAP");  	
	    	stringList.add("-host");
	    	stringList.add(hostname);
	    	stringList.add("-port");
	    	stringList.add(port);
	    	stringList.add("-lang");
	    	stringList.add("jython");
	    	if(security){
	    		stringList.add("-user");
		    	stringList.add(username);
		    	stringList.add("-password");
		    	stringList.add(password);
	    	}
	    	
	    	if( !wsadminClasspath.equalsIgnoreCase("")){
	    		stringList.add("-wsadmin_classpath");
	    		stringList.add(wsadminClasspath);
	    	}
	    	stringList.add("-f");
	    	stringList.add(script);
	    	//stringList.add(parms);
	    	for(int i=0; i<params.length;i++){
	    		stringList.add(params[i]);
	    	}
	    	String[] itemArray = new String[stringList.size()];
	    	String[] returnedArray = stringList.toArray(itemArray);
	    	
	    	logger.info(stringList);
	    	logger.info((new StringBuilder("*********************")).append(shell.getConnectionType()).toString());
            shell.run(returnedArray);
            logger.info("Script Return Code: ********** "+shell.getReturnCode());
            return shell.getReturnCode();
           
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
	    return -1;
	}
	public com.uft.was.config.Xml retrieveServerCfgInfo(String nodeName,String serverName, String clusterName) throws Exception{
		com.uft.was.config.Xml xml = null;
		
		if(isConnected()){
				//use the JAXB to build the XML file from the template..
				JAXBContext jc = JAXBContext.newInstance( "com.uft.was.config" );
				ObjectFactory objFactory = new ObjectFactory();
				xml=objFactory.createXml();
				Session session = new Session();
				ObjectName server = getConfigService().resolve(session, (new StringBuilder("Node="))
							.append(nodeName)
							.append(":Server=")
							.append(serverName).toString())[0];
				ObjectName pattern = ConfigServiceHelper.createObjectName(null, "Server");
				ObjectName configData[] = configService.queryConfigObjects(session, server, pattern, null);
				for(int i = 0; i < configData.length; i++){
					// get the Process Definitions
					List processList = (ArrayList)configService.getAttribute(session, configData[i], "processDefinitions");
					// initiate the Process Definitation JAXB object from the XSD template
					xml.setProcessDefinition(objFactory.createProcessDefinitionDetails());
					//initate the JVM Details Defination JAXB Oject from the XSD template;
					xml.getProcessDefinition().setJVM(objFactory.createJVMDetails());			
					for(Iterator iterator2 = processList.iterator(); iterator2.hasNext();){
						AttributeList process = (AttributeList)iterator2.next();
						ArrayList obj = (ArrayList)ConfigServiceHelper.getAttributeValue(process, "jvmEntries");
						for(Iterator iterator5 = obj.iterator(); iterator5.hasNext();){
							 Object object = iterator5.next();
							 Object value = ConfigServiceHelper.getAttributeValue((AttributeList)object, "initialHeapSize");
							 if(value != null){
								 //Integer initialHeapSize = (Integer)value;
								 //get initialHeapSize
								 xml.getProcessDefinition().getJVM().setInitialHeapSize(String.valueOf(value));
							 }
							 value = ConfigServiceHelper.getAttributeValue((AttributeList)object, "maximumHeapSize");
							 if(value != null){
								// Integer maxHeapSize = (Integer)value;
								 xml.getProcessDefinition().getJVM().setMaximumHeapSize(String.valueOf(value));
							 }
							 value = ConfigServiceHelper.getAttributeValue((AttributeList)object, "genericJvmArguments");
							 if(value != null){
								 xml.getProcessDefinition().getJVM().setMaximumHeapSize(String.valueOf(value));
							 }
							 value = ConfigServiceHelper.getAttributeValue((AttributeList)object, "verboseModeGarbageCollection");
							 if(value != null){
								 Boolean verboseModeGarbageCollection = (Boolean)value;
								
								 if(verboseModeGarbageCollection.booleanValue()){
									 xml.getProcessDefinition().getJVM().setEnableVerboseGarbageCollection(YesNoDefinition.YES);
								 }else{
									 xml.getProcessDefinition().getJVM().setEnableVerboseGarbageCollection(YesNoDefinition.NO);
								 }
								 
							 }
							 value = ConfigServiceHelper.getAttributeValue((AttributeList)object, "classpath");
							 if(value != null){
								 xml.getProcessDefinition().getJVM().setClasspath(String.valueOf(value));
							 }
							 ArrayList systemPropertyList = (ArrayList)ConfigServiceHelper.getAttributeValue((AttributeList)object, "systemProperties");
							 for(Iterator iterator6 = systemPropertyList.iterator(); iterator6.hasNext();){
								 Object obj6 = iterator6.next();
								 Object name6 = ConfigServiceHelper.getAttributeValue((AttributeList)obj6, "name");
								 Object value6 = ConfigServiceHelper.getAttributeValue((AttributeList)obj6, "value");
								 if(name6 == null || value6 == null){
									break; 
								 }
								CustomPropertyDetails propDetail= objFactory.createCustomPropertyDetails();
								propDetail.setName((String)name6);
								propDetail.setValue((String)value6);
								xml.getProcessDefinition().getJVM().setCustomProperty(propDetail);
								 
							 }  // end of the systemProperties loop
							
						} //end of the JVMEntries For Loop
							
					}  // end of the ProcessDefinition For Loop
					List errorStreamRedirectList = (ArrayList)configService.getAttribute(session, configData[i], "errorStreamRedirect ");
					
					
				
					// end of main For loop
				}
				
		}
		return xml;
		
		
	}
			
	
	public static Logger getLogger() {
		return logger;
	}
	public static void setLogger(Logger logger) {
		WasConnectorManager.logger = logger;
	}
	public boolean isRegisterListener() {
		return registerListener;
	}
	public void setRegisterListener(boolean registerListener) {
		this.registerListener = registerListener;
	}
	public AdminClient getAdminClient() {
		return adminClient;
	}
	public void setAdminClient(AdminClient adminClient) {
		this.adminClient = adminClient;
	}
	
	public void setConfigService(ConfigService configService) {
		this.configService = configService;
	}
	public String getHostname() {
		return hostname;
	}
	public void setHostname(String hostname) {
		this.hostname = hostname;
	}
	public String getPort() {
		return port;
	}
	public void setPort(String port) {
		this.port = port;
	}
	public Boolean getSecurity() {
		return security;
	}
	public void setSecurity(Boolean security) {
		this.security = security;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getSoapCfgURL() {
		return soapCfgURL;
	}
	public void setSoapCfgURL(String soapCfgURL) {
		this.soapCfgURL = soapCfgURL;
	}
	public String getSslCfgURL() {
		return sslCfgURL;
	}
	public void setSslCfgURL(String sslCfgURL) {
		this.sslCfgURL = sslCfgURL;
	}
	public String getTrustStore() {
		return trustStore;
	}
	public void setTrustStore(String trustStore) {
		this.trustStore = trustStore;
	}
	public String getTrustPassword() {
		return trustPassword;
	}
	public void setTrustPassword(String trustPassword) {
		this.trustPassword = trustPassword;
	}
	public String getKeyPassword() {
		return keyPassword;
	}
	public void setKeyPassword(String keyPassword) {
		this.keyPassword = keyPassword;
	}
	public String getKeyStore() {
		return keyStore;
	}
	public void setKeyStore(String keyStore) {
		this.keyStore = keyStore;
	}
	public String getWasInstallPath() {
		return wasInstallPath;
	}
	public void setWasInstallPath(String wasInstallPath) {
		this.wasInstallPath = wasInstallPath;
	}
	public String getRootFolder() {
		return rootFolder;
	}
	public void setRootFolder(String rootFolder) {
		this.rootFolder = rootFolder;
	}
	public WasManagementListener getListener() {
		return listener;
	}
	public void setListener(WasManagementListener listener) {
		this.listener = listener;
	}

	public String getSoapRequestTimeout() {
		return soapRequestTimeout;
	}

	public void setSoapRequestTimeout(String soapRequestTimeout) {
		this.soapRequestTimeout = soapRequestTimeout;
	}

	public void setConnected(boolean connected) {
		this.connected = connected;
	}
	
	public boolean isConnected(){
		return this.connected;
	}
	public String getConfigScript() {
		return configScript;
	}
	public void setConfigScript(String configScript) {
		this.configScript = configScript;
	}
	public String getProfileName() {
		return profileName;
	}
	public void setProfileName(String profileName) {
		this.profileName = profileName;
	}
	public String getRegion() {
		return region;
	}
	public void setRegion(String region) {
		this.region = region;
	}
	public Date getInitDate() {
		return initDate;
	}
	public void setInitDate(Date initDate) {
		this.initDate = initDate;
	}
	public String getWsadminClasspath() {
		return wsadminClasspath;
	}
	public void setWsadminClasspath(String wsadminClasspath) {
		this.wsadminClasspath = wsadminClasspath;
	}
	
	
}
